package com.group3.controller;

import com.group3.common.result.ApiResponse;
import com.group3.service.BehaviorAnalysisService;
import com.group3.vo.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 行为分析控制器
 */
@RestController
@RequestMapping("/analysis")
public class BehaviorAnalysisController {

    @Resource
    private BehaviorAnalysisService behaviorAnalysisService;

    /**
     * 获取用户行为统计数据
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/user/{userId}")
    public ApiResponse<UserBehaviorStatsVO> getUserBehaviorStats(@PathVariable Long userId) {
        UserBehaviorStatsVO vo = behaviorAnalysisService.getUserBehaviorStats(userId);
        return ApiResponse.success(vo);
    }

    /**
     * 获取商品行为统计数据
     * @param productId 商品ID
     * @return
     */
    @GetMapping("/product/{productId}")
    public ApiResponse<ProductBehaviorStatsVO> getProductBehaviorStats(@PathVariable Long productId) {
        ProductBehaviorStatsVO vo = behaviorAnalysisService.getProductBehaviorStats(productId);
        return ApiResponse.success(vo);
    }

    /**
     * 获取直播间统计数据
     * @param liveId 直播间ID
     * @return
     */
    @GetMapping("/live/{liveId}")
    public ApiResponse<LiveRoomStatsVO> getLiveRoomStats(@PathVariable Long liveId) {
        LiveRoomStatsVO vo = behaviorAnalysisService.getLiveRoomStats(liveId);
        return ApiResponse.success(vo);
    }

    /**
     * 批量获取用户画像数据
     * @param userIds 用户ID列表
     * @return
     */
    @GetMapping("/profiles")
    public ApiResponse<List<UserProfileVO>> getUserProfiles(@RequestParam List<Long> userIds) {
        List<UserProfileVO> profiles = behaviorAnalysisService.getUserProfiles(userIds);
        return ApiResponse.success(profiles);
    }

    /**
     * 获取用户个性化推荐商品列表
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/recommendations/{userId}")
    public ApiResponse<List<RecommendationVO>> getRecommendations(@PathVariable Long userId) {
        List<RecommendationVO> recommendations = behaviorAnalysisService.getRecommendations(userId);
        return ApiResponse.success(recommendations);
    }
}
